/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jpAgregarTipo.java
 *
 * Created on 18-nov-2010, 8:36:50
 */

package Suministros;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Utiles_MensajesDialogo;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import suministros.ejb30.TO.TipoTO;

/**
 *
 * @author Diana
 */
public class jpAgregarTipo extends javax.swing.JDialog {
    String tabla;
    String campo;
    jifAdministrarTipos vpadre;
    Frame padre;
    boolean estado;
    /** Creates new form jpAgregarTipo */
    public jpAgregarTipo(jifAdministrarTipos vpadre,java.awt.Frame padre,java.awt.Frame parent, boolean modal,String tabla, String descripcion_campo, Boolean estado) {
        super(parent, modal);
        this.initComponents();
        this.padre=padre;
        this.vpadre=vpadre;
        this.tabla=tabla;
        this.campo=descripcion_campo;
        this.jtfTabla.setText(tabla);
        this.jtfDescripcionCampo.setText(descripcion_campo);
        this.jtfTabla.setEditable(false);
        this.jtfDescripcionCampo.setEditable(estado);
    }
    public boolean verificar(){
        boolean verifica=true;
        if(this.jtfCodigo.getText().compareTo("")==0){
            verifica=false;
        }
        if(this.jtfDescripcionValor.getText().compareTo("")==0){
            verifica=false;
        }
        return verifica;
    }
    public void registrar(){

        TipoTO tipo= new TipoTO();
        tipo.setTabla(this.jtfTabla.getText());
        tipo.setDescripcion_campo(this.jtfDescripcionCampo.getText());
        tipo.setDescripcion_valor(this.jtfDescripcionValor.getText());
        tipo.setCodigo(this.jtfCodigo.getText());
        vpadre.llenarTabla(tipo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtfTabla = new javax.swing.JTextField();
        jtfDescripcionCampo = new javax.swing.JTextField();
        jtfCodigo = new javax.swing.JTextField();
        jtfDescripcionValor = new javax.swing.JTextField();
        jbtAceptar = new javax.swing.JButton();
        jbtCancelar = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel1.setText("TABLA:");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel2.setText("DESCRIPCION CAMPO:");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel3.setText("CODIGO:");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel4.setText("DESCRIPCION VALOR:");

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });
        jbtAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtAceptarKeyPressed(evt);
            }
        });

        jbtCancelar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbtCancelar.setMnemonic('C');
        jbtCancelar.setText("CERRAR");
        jbtCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                            .addComponent(jtfDescripcionCampo, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                            .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfDescripcionValor, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(125, 125, 125)
                                .addComponent(jbtCancelar))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jbtAceptar)
                                .addGap(117, 117, 117)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfTabla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfDescripcionCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtfDescripcionValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtAceptar)
                    .addComponent(jbtCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea modificar el grupo de suministro ?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            if(verificar()){
                this.registrar();
            }
            else{
                Utiles_MensajesDialogo.mensajeAlerta("No se han ingresado todos los datos");
            }

        }
}//GEN-LAST:event_jbtAceptarActionPerformed

    private void jbtAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtAceptarKeyPressed
        if(KeyEvent.VK_ENTER == evt.getKeyCode() ||KeyEvent.VK_TAB == evt.getKeyCode()  ){
            this.jbtAceptar.doClick();
        }
}//GEN-LAST:event_jbtAceptarKeyPressed

    private void jbtCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCancelarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jbtCancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public javax.swing.JButton jbtAceptar;
    private javax.swing.JButton jbtCancelar;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JTextField jtfDescripcionCampo;
    private javax.swing.JTextField jtfDescripcionValor;
    private javax.swing.JTextField jtfTabla;
    // End of variables declaration//GEN-END:variables

}
